package com.ityuwen.mengyagushi.order.listener;

import com.ityuwen.mengyagushi.common.constant.KafkaConstant;
import com.ityuwen.mengyagushi.common.constant.SystemConstant;
import com.ityuwen.mengyagushi.order.service.OrderInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class OrderListener {

    @Autowired
    private OrderInfoService orderInfoService;

    @KafkaListener(topics = KafkaConstant.QUEUE_ORDER_PAY_SUCCESS)
    public void paySuccess(String orderNo){
        if (StringUtils.isBlank(orderNo)){
            return;
        }

        this.orderInfoService.updateStatus(orderNo, SystemConstant.ORDER_STATUS_UNPAID, SystemConstant.ORDER_STATUS_PAID);
    }
}
